package com.ln.lnzw.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.ActivityUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.google.gson.Gson;
import com.ln.lnzw.R;
import com.ln.lnzw.adapter.ImplementationSubjectAdapter;
import com.ln.lnzw.app.AppConstant;
import com.ln.lnzw.base.BaseActivity;
import com.ln.lnzw.bean.NewImplementationSubjectBean;
import com.ln.lnzw.utils.CacheActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wuwei on 2018/6/7.
 * 我的咨询选择部门页面
 */

public class ConsultingDepartmentActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.rv_recyclerview)
    RecyclerView rvRecyclerview;
    private ImplementationSubjectAdapter mAdapter;
    private List<NewImplementationSubjectBean.ResultBean> mList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.consulting_department_activity);
        ButterKnife.bind(this);
        CacheActivity.addActivity(ConsultingDepartmentActivity.this);
        setView();
        initData();

    }

    private void initData() {
        Gson gson = new Gson();
        NewImplementationSubjectBean newImplementationSubjectBean = gson.fromJson(activity.spUtils.getString(AppConstant.IMPLEMENTATION),NewImplementationSubjectBean.class);
        if (mList != null || !mList.isEmpty()) {
            mList.clear();
        }
        mList.addAll(newImplementationSubjectBean.getResult());
        mAdapter.notifyDataSetChanged();
    }

    private void setView() {
        rvRecyclerview.setNestedScrollingEnabled(false);
        rvRecyclerview.setLayoutManager(new GridLayoutManager(activity, 2));
        mAdapter = new ImplementationSubjectAdapter(R.layout.item_implementation_subject, mList);
        rvRecyclerview.setAdapter(mAdapter);

        rvRecyclerview.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                Bundle b = new Bundle();
                b.putString("cDesc",mList.get(position).getGroupId());
                b.putString("name",mList.get(position).getGroupName());
                ActivityUtils.startActivity(b,activity,ConsultationDepartmentMattersActivity.class);
            }
        });
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
